package com.hwy.struts.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.hwy.struts.dao.SysUserDao;
import com.hwy.struts.domain.SysUser;
import com.hwy.struts.utils.HibernateUtil;

public class SysUserDaoImp implements SysUserDao {

	@Override
	public SysUser login(SysUser sUser) throws Exception {
		Session currentSession = HibernateUtil.getCurrentSession();
		Transaction beginTransaction = currentSession.beginTransaction();
		Query createQuery = currentSession.createQuery("from SysUser where user_code = ? and user_password = ?");
		// HQL设置参数
		createQuery.setParameter(0, sUser.getUser_code());
		createQuery.setParameter(1, sUser.getUser_password());
		SysUser uniqueResult = (SysUser)createQuery.uniqueResult();
		beginTransaction.commit();
		return uniqueResult;
	}

}
